/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.database.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 * @author Valdigleis
 */
public class CreateTables {
    
    private Connection connection;
    
    public CreateTables(){
        this.connection = ConnectionDataBase.getConnection();
    }
    
    public void createTablePessoa(){
        String sql = null;
        try{        
            sql = "CREATE TABLE PESSOAS( " +
                   "id_pessoa integer not null GENERATED ALWAYS AS " +
                   "IDENTITY (START WITH 1, INCREMENT BY 1) " +
                   "CONSTRAINT PK_PESSOAS PRIMARY KEY, " +
                   "nome varchar(20) not null, " +
                   "idade integer not null" +
                   ")";
            
            PreparedStatement stmt = this.connection.prepareStatement(sql);
            stmt.execute();
            stmt.close();
            System.out.println("CreateTables.createTablePessoas Ok!");       
        }catch(SQLException e){
            System.err.println("O erro foi na execeção de Salvar em Criar Tabelas");
            e.printStackTrace();
        }
    }
    
    public void createTableTelefone(){
        String sql = null;
        try{
            sql = "CREATE TABLE TELEFONES( " +
                    "id_fone integer not null GENERATED ALWAYS AS " +
                    "IDENTITY (START WITH 1, INCREMENT BY 1) " +
                    "CONSTRAINT PK_TEFEFONES PRIMARY KEY, " +
                    "numero varchar(12), " +
                    "tipo varchar(11), " +
                    "pessoa integer not null, " +
                    "CONSTRAINT FK_PESSOAS FOREIGN KEY (pessoa) " +
                    "REFERENCES PESSOAS (id_pessoa) " +
                    ")";
            PreparedStatement stmt = this.connection.prepareStatement(sql);
            stmt.execute();
            stmt.close();
            System.out.println("CreateTables.createTableTelefones Ok!");
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
    
}
